package com.lanou.dllo.vc.activity;

import android.view.View;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;

import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMChatOptions;
import com.lanou.dllo.vc.R;
import com.lanou.dllo.vc.view.SwitchButton;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by dllo on 15/12/3.
 */
public class NewsCuesActivity extends BaseActivity {
    @Bind(R.id.newsCuesSb)
    SwitchButton newsCuesSb;
    @Bind(R.id.voiceSb)
    SwitchButton voiceSb;
    @Bind(R.id.vibrationSb)
    SwitchButton vibrationSb;
    @Bind(R.id.voiceRelativeLayout)
    RelativeLayout voiceRelativeLayout;
    @Bind(R.id.vibrationRelativeLayout)
    RelativeLayout vibrationRelativeLayout;
    @Bind(R.id.playWithSpeakerSb)
    SwitchButton playWithSpeakerSb;
    @Bind(R.id.notificationSb)
    SwitchButton notificationSb;
    @Bind(R.id.validationSb)
    SwitchButton validationSb;
    private EMChatOptions chatOptions;

    @Override
    protected int getLayout() {
        return R.layout.activity_news_cues;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initData() {

        chatOptions = EMChatManager.getInstance().getChatOptions();
        if (newsCuesSb.isChecked()) {
            voiceRelativeLayout.setVisibility(View.VISIBLE);
            vibrationRelativeLayout.setVisibility(View.VISIBLE);
        }else {
            voiceRelativeLayout.setVisibility(View.GONE);
            vibrationRelativeLayout.setVisibility(View.GONE);
        }

        newsCuesSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    voiceRelativeLayout.setVisibility(View.VISIBLE);
                    vibrationRelativeLayout.setVisibility(View.VISIBLE);
                    chatOptions.setNotifyBySoundAndVibrate(true);

                }else {

                    voiceRelativeLayout.setVisibility(View.GONE);
                    vibrationRelativeLayout.setVisibility(View.GONE);
                    chatOptions.setNotifyBySoundAndVibrate(false);
                }
            }
        });
        voiceSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    chatOptions.setNoticeBySound(true); //默认为true 开启声音提醒
                }else {
                    chatOptions.setNoticeBySound(false); //默认为true 开启声音提醒
                }
            }
        });
        vibrationSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    chatOptions.setNoticedByVibrate(true); //默认为true 开启震动提醒
                }else {
                    chatOptions.setNoticedByVibrate(false); //默认为true 开启震动提醒
                }
            }
        });
        playWithSpeakerSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    chatOptions.setUseSpeaker(true); //默认为true 开启扬声器播放
                }else {
                    chatOptions.setUseSpeaker(false); //默认为true 开启扬声器播放
                }
            }
        });
        notificationSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    chatOptions.setShowNotificationInBackgroud(true); //默认为true
                }else {
                    chatOptions.setShowNotificationInBackgroud(false); //默认为true
                }
            }
        });
        validationSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    chatOptions.setAcceptInvitationAlways(false);
                }else {
                    chatOptions.setAcceptInvitationAlways(true);
                }
            }
        });
    }
}
